package com.hxwm.hwdbtool.controller;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import org.apache.log4j.Logger;

/**
 * @program: hwdbtool
 * @ClassName ExportDataController
 * @description:
 * @author: hxwm
 * @create: 2024-05-12 19:00
 * @Version 1.0
 **/
public class ExportDataController {
    Logger logger = Logger.getLogger(ExportDataController.class);
    @FXML
    private HBox exportFormHBox;
    @FXML
    private ComboBox exportTypeComboBox;

    @FXML
    private ComboBox exportFileFormComboBox;
    @FXML
    private ComboBox exportCharacterSetComboBox;
    private ComboBox chooseExportTableComboBox;
    private Label chooseExportTableLabel;

    @FXML
    private Button chooseMapperFileBtn;
    @FXML
    private TextField mapperFileTextField;
    private void initialize(){

        exportFormHBox.setSpacing(10.0);
        ToggleGroup exportFormGroup = new ToggleGroup();
        RadioButton exportOnlyDataBtn = new RadioButton("仅数据");
        RadioButton exportOnlyStructBtn = new RadioButton("仅结构");
        RadioButton exportDataStructBtn = new RadioButton("数据和结构");
        exportOnlyDataBtn.setToggleGroup(exportFormGroup);
        exportOnlyStructBtn.setToggleGroup(exportFormGroup);
        exportDataStructBtn.setToggleGroup(exportFormGroup);
        exportOnlyDataBtn.setDisable(true);
        exportOnlyStructBtn.setDisable(true);
        exportDataStructBtn.setDisable(true);
        exportOnlyDataBtn.setPrefSize(100,40);
        exportOnlyStructBtn.setPrefSize(100,40);
        exportDataStructBtn.setPrefSize(120,40);
        exportFormHBox.getChildren().addAll(exportOnlyDataBtn,exportOnlyStructBtn,exportDataStructBtn);


        ObservableList<String> exportTypeOptions = FXCollections.observableArrayList("批量导出", "单个导出");
        exportTypeComboBox.setItems(exportTypeOptions);
        exportTypeComboBox.setValue("批量导出");
        exportTypeComboBox.valueProperty().addListener((observable, oldValue, newValue)->{
            if("批量导出".equals(newValue)){
                chooseExportTableComboBox.setDisable(true);
                chooseExportTableLabel.setDisable(true);
                exportOnlyDataBtn.setDisable(true);
                exportOnlyStructBtn.setDisable(true);
                exportDataStructBtn.setDisable(true);
                chooseMapperFileBtn.setDisable(false);
                mapperFileTextField.setDisable(false);
            }
            if("单个导出".equals(newValue)){
                chooseExportTableComboBox.setDisable(false);
                chooseExportTableLabel.setDisable(false);
                exportOnlyDataBtn.setDisable(false);
                exportOnlyStructBtn.setDisable(false);
                exportDataStructBtn.setDisable(false);
                chooseMapperFileBtn.setDisable(true);
                mapperFileTextField.setDisable(true);
            }
        });

    }

}